package com.molin.extensionTest.getFieldModel;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo4 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Class clazz = Class.forName("com.molin.extensionTest.getFieldModel.Student");
        Method sayHi = clazz.getDeclaredMethod("sayHi");
        System.out.println(sayHi);

        Method sayHiName = clazz.getDeclaredMethod("sayHi", String.class);
        System.out.println(sayHiName);

        //获取obj
        Student student = (Student) clazz.newInstance();
        //运行方法
        sayHi.invoke(student);
        sayHiName.invoke(student,"hahaheihei");
    }
}
